home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2888 / 2888.xpi / content / options.js < prev    next >
Text File  |  2008-06-29  |  9KB  |  248 lines

  1. var cookieManager = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager);
  2. var prefs = Components.classes["@mozilla.org/preferences-service;1"].
  3.     getService(Components.interfaces.nsIPrefService).getBranch("gmarks");
  4. var GMS=Components.classes["@mozilla.org/gmarks;1"]
  5.                      .getService(Components.interfaces.nsIGMarksService).wrappedJSObject;
  6. var strbundle;
  7. var isSignedIn, calls=0, nestedChar, qsShortcut, chkQS, qsKeyCode,menu_list=null,menu_list_options=null;
  8. var commandIDs=["addeditbookmark","removebookmark","organize","gotosite", //bookmarktabs
  9.         "options","editfilters","refresh","separator","mostrecent","mostused",
  10.         "bookmarkstree"];
  11.  
  12. function initWindow(event){
  13.   strbundle=document.getElementById("gmarksBundle");
  14.   initQSKey();
  15.   initPassInfo();
  16.   initMenuConfig();
  17.   initVisList();
  18.   document.getElementById("grShow").checked=document.getElementById('grLabel').value!="";
  19. }
  20. function initQSKey(){//for the key that triggers the Quick Search
  21.   qsShortcut=document.getElementById("qsShortcut");
  22.   chkQS=document.getElementById("disableQS");
  23.   qsKeyCode=GMS.qsKeyCode;
  24.   if (GMS.qsKeyCode==-1){
  25.     chkQS.checked=true;
  26.     qsShortcut.value="Disabled";
  27.   }
  28.   else{
  29.     qsShortcut.value=getKeyCodeText(qsKeyCode);
  30.   }
  31. }
  32. function initPassInfo(){
  33.   try{
  34.     var pass=GMS.getPassInfo();
  35.     if (pass!=null){
  36.       document.getElementById("txtEmail").value=pass.user;
  37.       document.getElementById("txtPassword").value=pass.password;
  38.     }
  39.   }
  40.   catch(e){}
  41. }
  42. function initMenuConfig(){
  43.   if (!menu_list)
  44.     menu_list=document.getElementById("gmarks_menu_items");
  45.   while(menu_list.firstChild)
  46.     menu_list.removeChild(menu_list.lastChild);
  47.   if (!menu_list_options)
  48.     menu_list_options=document.getElementById("unused_gmarks_menu_items");
  49.   while(menu_list_options.firstChild)
  50.     menu_list_options.removeChild(menu_list_options.lastChild);
  51.   var menupref=document.getElementById("pDisplay").preferenceForElement(menu_list).value;//prefs.getCharPref(".menu.items");
  52.   var itemIDs=menupref.split(",");
  53.   var unusedIDs=commandIDs.slice();
  54.   itemIDs.forEach(function(id,idx,arr){
  55.     menu_list.appendChild(createListItem(id));
  56.     if (id!="separator"){
  57.       var pos=unusedIDs.indexOf(id);
  58.       unusedIDs.splice(pos,1);
  59.     }
  60.   });
  61.   unusedIDs.forEach(function(id,idx,arr){
  62.     var ele=createListItem(id);
  63.     menu_list_options.appendChild(ele);
  64.   });
  65.   menu_list.setAttribute("value",itemIDs.join(","));
  66.   menu_list_options.setAttribute("value",unusedIDs.join(","));
  67.   menu_list.value=itemIDs.toString();//itemIDs.join(",");
  68.   menu_list_options.value=unusedIDs.join(",");
  69.   menu_list.selectedItem=menu_list.firstChild;
  70.   menu_list_options.selectedItem=menu_list_options.firstChild;
  71.  
  72. }
  73. function getMenuListBoxValue(event){
  74.   return menu_list.getAttribute("value");
  75. }
  76. function addItemToMenu(event){
  77.   /* Get selected ele to move */
  78.   if (!menu_list_options.selectedItem) return;
  79.   var id=menu_list_options.selectedItem.value;
  80.   if (id!="separator"){
  81.     menu_list_options.removeChild(menu_list_options.selectedItem);
  82.     menu_list_options.selectedItem=menu_list_options.firstChild;
  83.   }
  84.   menu_list.appendChild(createListItem(id));
  85.   var val=menu_list.getAttribute("value");
  86.   if (val && val.length!=0) val+=",";
  87.   val+=id;
  88.   menu_list.setAttribute("value",val);
  89.   menu_list.selectedItem=menu_list.lastChild;
  90.   document.getElementById("pDisplay").userChangedValue(menu_list);
  91. }
  92. function removeItemFromMenu(event){
  93.   if (!menu_list.selectedItem) return;
  94.   var id=menu_list.selectedItem.value;
  95.   menu_list.removeChild(menu_list.selectedItem);
  96.   menu_list.selectedItem=menu_list.lastChild;
  97.   var ids=menu_list.getAttribute("value").split(",");
  98.   var pos=ids.indexOf(id);
  99.   ids.splice(pos,1);
  100.   menu_list.setAttribute("value",ids.join(","));
  101.   if (id!="separator")
  102.     menu_list_options.appendChild(createListItem(id));
  103.   document.getElementById("pDisplay").userChangedValue(menu_list);
  104. }
  105. function resetMenuDefaults(event){
  106.   document.getElementById("pDisplay").preferenceForElement(menu_list).reset();
  107.   initMenuConfig();
  108. }
  109. function moveUpInMenuList(event){
  110.   var sel=menu_list.selectedItem;
  111.   var idx=menu_list.selectedIndex;
  112.   if (!sel || idx==0) return;
  113.   var ids=menu_list.getAttribute("value").split(",");
  114.   var tmp=ids[idx];
  115.   ids[idx]=ids[idx-1];
  116.   ids[idx-1]=tmp;
  117.   menu_list.setAttribute("value",ids.join(","));
  118.   menu_list.insertBefore(sel,sel.previousSibling);
  119.   menu_list.selectedIndex=idx-1;
  120.   menu_list.ensureIndexIsVisible(idx-1);
  121.   document.getElementById("pDisplay").userChangedValue(menu_list);
  122. }
  123. function moveDownInMenuList(event){
  124.   var sel=menu_list.selectedItem;
  125.   var idx=menu_list.selectedIndex;
  126.   if (!sel || idx==menu_list.childNodes.length-1) return;
  127.   var ids=menu_list.getAttribute("value").split(",");
  128.   var tmp=ids[idx];
  129.   ids[idx]=ids[idx+1];
  130.   ids[idx+1]=tmp;
  131.   menu_list.setAttribute("value",ids.join(","));
  132.   menu_list.insertBefore(sel,sel.nextSibling.nextSibling);
  133.   menu_list.selectedIndex=idx+1;
  134.   menu_list.ensureIndexIsVisible(idx+1);
  135.   document.getElementById("pDisplay").userChangedValue(menu_list);
  136. }
  137. function createListItem(id){
  138.   var ele=document.createElement("listitem");
  139.   ele.id="menu_"+id;
  140.   ele.value=id;
  141.   ele.setAttribute("id","menu_id");
  142.   try{
  143.   ele.setAttribute("label",GMS.strbundle.GetStringFromName(id));
  144.   }catch(e){dump("error creating "+id+"\n"+e+"\n")};
  145.   return ele;
  146. }
  147. function initVisList(){
  148.   if (GMS.mode!="simpy") return;
  149.   document.getElementById("visGroup").hidden=false;
  150. }
  151.  
  152. function toggleGoogleReader(){
  153.   var checked=document.getElementById('grShow').checked;
  154.   var txt=document.getElementById("grLabel");
  155.   if (!checked)
  156.     txt.value="";
  157.   else
  158.     txt.value="Google Reader";
  159.   document.getElementById("pOther").preferenceForElement(txt).value=txt.value;
  160. }
  161. function getQSShortcut(event){
  162.   return qsKeyCode;
  163. }
  164. function getKeyCodeText(keyCode){
  165.   var event=Components.interfaces.nsIDOMKeyEvent;
  166.   for (var p in event){
  167.     if (p.toString().substring(0,7)=="DOM_VK_" && event[p]==keyCode){
  168.       return p.toString().substring(7,8)+p.toString().substring(8).toLowerCase();
  169.     }
  170.   }
  171. }
  172. function changeQSShortcut(event){
  173.   if (event.keyCode==13 || event.keyCode==27) return;
  174.   chkQS.checked=false;
  175.   qsKeyCode=event.keyCode;
  176.   qsShortcut.value=getKeyCodeText(qsKeyCode);
  177.   event.stopPropagation();
  178.   document.getElementById("pOther").userChangedValue(event.target.parentNode);
  179. }
  180. function disableQSCMD(){
  181.   if (chkQS.checked){
  182.     qsShortcut.value='Disabled';
  183.     qsKeyCode=-1;
  184.   }else{
  185.     if (qsShortcut.value=='Disabled'){
  186.       if (GMS.qsKeyCode!=-1){
  187.         var key=getKeyCodeText(GMS.qsKeyCode);
  188.         qsShortcut.value=key;//.substring(3,4)+key.substring(4).toLowerCase();
  189.         qsKeyCode=GMS.qsKeyCode;
  190.       }
  191.       else{
  192.         qsShortcut.value='Home';
  193.         qsKeyCode=36;
  194.       }
  195.     }
  196.   }
  197.   document.getElementById("pOther").userChangedValue(qsShortcut.parentNode);
  198. }
  199. function onShowFavPress()
  200. {
  201.   document.getElementById("validateFavicons").setAttribute('disabled',!document.getElementById("showFavicons").checked);
  202. }
  203. function saveLogin(event){
  204.   if (document.documentElement.instantApply){
  205.     var email=document.getElementById("txtEmail").value;
  206.     var password=document.getElementById("txtPassword").value;
  207.     GMS.savePassInfo(email,password);
  208.   }
  209. }
  210. function onAccept(event){
  211.   var carryon=true;
  212.   if (carryon){
  213.     var email=document.getElementById("txtEmail").value;
  214.     var password=document.getElementById("txtPassword").value;
  215.     if (email.length>0 && password.length>0)
  216.       GMS.savePassInfo(email,password);
  217.     if (GMS.mode=="simpy"){
  218.       var list=document.getElementById("visList");
  219.       var visibility=list.selectedIndex;
  220.       prefs.setIntPref(".visibility",visibility);
  221.       GMS.com.loadSimpyPrefs();
  222.     }
  223.     GMS.loadPrefs(); GMS.doCommand('quickrefresh');
  224.   }
  225.   return carryon;
  226. }
  227. function doCancel(event){
  228.   var carryon=true;
  229.   if (document.documentElement.instantApply){
  230.     //dump("refresh\n");
  231.     GMS.loadPrefs();
  232.     if (GMS.mode=="simpy"){
  233.       var list=document.getElementById("visList");
  234.       var visibility=list.selectedIndex;
  235.       prefs.setIntPref(".visibility",visibility);
  236.       GMS.com.loadSimpyPrefs();
  237.     }
  238.     GMS.doCommand('quickrefresh');
  239.   }
  240.   return carryon;
  241. }
  242. function debug(msg){
  243.   /*var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
  244.         .getService(Components.interfaces.nsIConsoleService);
  245.     consoleService.logStringMessage(msg);
  246.     /**/
  247. }
  248.